package yourobot;

import org.jbox2d.callbacks.ContactImpulse;
import org.jbox2d.callbacks.ContactListener;
import org.jbox2d.collision.Manifold;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.contacts.Contact;

import yourobot.robots.Player;
/**
 * 
 * @author mehdimasrour
 *
 */
public class MyContactListener implements ContactListener {

	@Override
	public void beginContact(Contact contact) {
		if ( contact.getFixtureB().getUserData().equals("ia") && contact.getFixtureA().getUserData().equals("player") ){
			Player p = (Player)contact.getFixtureA().getBody().getUserData();
			Body b = contact.getFixtureB().getBody();
			float d = (b.getLinearVelocity().normalize()/2*(p.getLife()/2))/225;
			p.damage(d);
		}
		if ( contact.getFixtureA().getUserData().equals("ia") && contact.getFixtureB().getUserData().equals("player") ){
			Player p = (Player)contact.getFixtureA().getBody().getUserData();
			Body b = contact.getFixtureB().getBody();
			float d = (b.getLinearVelocity().normalize()/2*(p.getLife()/2))/225;
			p.damage(d);
		}
		
	}

	@Override
	public void endContact(Contact contact) {
		// TODO Auto-generated method stub

	}

	@Override
	public void postSolve(Contact contact, ContactImpulse impulse) {
		// TODO Auto-generated method stub
	}

	@Override
	public void preSolve(Contact contact, Manifold oldManifold) {
		// TODO Auto-generated method stub

	}

}
